/**
 * 
 */
package persistence;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author fabiensaulnier
 * 
 */
public class PersistenceUtil {

	private static PersistenceConfiguration configuration;

	private static PersistenceSessionFactory factory;

	private static Logger log = LoggerFactory.getLogger(PersistenceSessionFactory.class);

	static {
		try {
			configuration = new PersistenceConfiguration();
			factory = configuration.getPersistenceSessionFactory();
		} catch (Throwable ex) {
			log.error("Building PersistenceContextFactory failed.", ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static PersistenceConfiguration getConfiguration() {
		return configuration;
	}

	public static PersistenceSessionFactory getFactory() {
		return factory;
	}

	public static void setPersistenceConfiguration(PersistenceConfiguration persistenceConfiguration) {
		configuration = persistenceConfiguration;
		factory = PersistenceUtil.getFactory(configuration);
	}

	public static PersistenceSessionFactory getFactory(PersistenceConfiguration configuration2) {
		PersistenceUtil.factory = new PersistenceSessionFactory(configuration);
		return factory;
	}
}